package array.simple;

public class TruncateSentence_1816 {

    public String truncateSentence(String s, int k) {
        int i = 0;
        int j = 0;
        while(j < s.length()) {
            if (s.charAt(j) == ' ') {
                i++;
                if (i == k) {
                    break;
                }
            }
            j++;
        }
        return s.substring(0, j);
    }

    public static void main(String[] args) {
        TruncateSentence_1816 tt = new TruncateSentence_1816();
        System.out.println(tt.truncateSentence("chopper is not a tanuki", 5));
    }
}
